package com.fesine.ch02.synBlockMoreObjectOneLock;

/**
 * @description: 静态同步方法与synchronized(class)代码块
 * @author: Fesine
 * @createTime:2016/7/6 18:21
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/7/6 18:21
 */
public class Service {

    public static void printA() {
        synchronized (Service.class) {
            try {
                System.out.println("线程名称为：" + Thread.currentThread().getName() +
                        " 在 " + System.currentTimeMillis() + " 进入printA");
                Thread.sleep(3000);
                System.out.println("线程名称为：" + Thread.currentThread().getName() +
                        " 在 " + System.currentTimeMillis() + " 离开printA");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void printB() {
        synchronized (Service.class) {
            System.out.println("线程名称为：" + Thread.currentThread().getName() +
                    " 在 " + System.currentTimeMillis() + " 进入printB");
            System.out.println("线程名称为：" + Thread.currentThread().getName() +
                    " 在 " + System.currentTimeMillis() + " 离开printB");
        }
    }

}
